﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecreate.Model;
using Ecreate.Business;
using Ecreate.Data;
namespace Ecreate.Web.systemanage.customer
{
    public partial class forgetpassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.hid.Value = this.Request.QueryString["id"];
                t_customer user = new t_customer();
                user.Cus_id = this.hid.Value;
                user = FactoryDBEngine.SqlMapper().QueryForObject<t_customer>("t_customer_SelectByID", user.Cus_id);
                if (user != null)
                {

                    this.txt_question.Text = user.Passwordquestion;
                   
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            t_customer user = new t_customer();
            user.Cus_id = this.hid.Value;
            user = FactoryDBEngine.SqlMapper().QueryForObject<t_customer>("t_customer_SelectByID", user.Cus_id);
            if (user == null)
            {
                this.lbl_message.Text = "删除对像不存在,请刷新列表!";
                this.lbl_message.Visible = true;
                return;

            }
            if (user.Passwordanswer != this.txt_answer.Text)
            {
                this.lbl_message.Text = "答案错误!";
                this.lbl_message.Visible = true;
                return;

            }

            if (this.txt_password1.Text == "")
            {
                this.lbl_message.Text = "请输入新密码!";
                this.lbl_message.Visible = true;
                return;
            }
            if (this.txt_password2.Text == "")
            {
                this.lbl_message.Text = "请输入确定密码!";
                this.lbl_message.Visible = true;
                return;
            }


            if (this.txt_password1.Text!= this.txt_password2.Text)
            {
                this.lbl_message.Text = "两次输入密码不一致!";
                this.lbl_message.Visible = true;
                return;
            }
            CustomerService service = new CustomerService();
            user.Password = this.txt_password1.Text;
            WebResult<Object> result=service.UpdatePassword(user);
            this.lbl_message.Text = result.Message;
            this.lbl_message.Visible = true;

            Response.Write("<script type=\"text/javascript\" language=\"javascript\">          alert('数据保存成功!')　　; </script>");
            Response.Write("<script type=\"text/javascript\" language=\"javascript\">          window.parent.frames[\"client\"].location=\"/systemanage/customer/customerlist.aspx?areacode=" + user.Areacode + "\"　　; </script>");
          
        }
    }
}
